﻿using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Logging;
using Quartz;
using SXMeteorological.Data.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SXMeteorological.DataSyn.Rainfall
{
    public class RainfallJob:IJob
    {
        private readonly ILogger _logger;

        /// <summary>
        /// Job
        /// </summary>
        public RainfallJob()
        {
            _logger = LoggerFrameFactory.CreateLog();
            _logger.LogInfo("执行降雨量任务构造函数");
        }
        /// <summary>
        /// 执行  按要素  + 地区 +小时要素或者日要素要生成
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
          //  _logger.LogInfo("执行降雨量任务");
            HourRainfall();
            Hour3Rainfall();
            Hour6Rainfall();
            Hour12Rainfall();
            Hour24Rainfall();
            DayRainFull0808();
            DayRainFull0820();
            DayRainFull2008();
            DayRainFull2020();
        }
      
        #region
        /// <summary>
        /// 过去一小时降水
        /// </summary>
        private void HourRainfall()
        {
            try
            {
                //参数
                
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_1h";
                string featureName = "过去1小时降水量";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "SURF_CHN_MUL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall1.txt";
                CreateMap.CreateFeatureMap(interfaceName,returnValue, dataCode, featureName, "逐小时降雨量图", time, colorpath,"h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 过去3小时降水量
        /// </summary>
        private void Hour3Rainfall()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_3h";
                string featureName = "过去3小时降水量";
                string dataCode = "SURF_CHN_MUL_HOR";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall3.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "3小时降水量图", time, colorpath, "h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 过去6小时降水量
        /// </summary>
        private void Hour6Rainfall()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_6h";
                string featureName = "过去6小时降水量";
                string dataCode = "SURF_CHN_MUL_HOR";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall6.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "6小时降水量图", time, colorpath, "h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 过去12小时降水量
        /// </summary>
        private void Hour12Rainfall()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_12h";
                string featureName = "过去12小时降水量";
                string dataCode = "SURF_CHN_MUL_HOR";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall12.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "12小时降水量图", time, colorpath, "h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 过去24小时降水量
        /// </summary>
        private void Hour24Rainfall()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_24h";
                string featureName = "过去24小时降水量";
                string dataCode = "SURF_CHN_MUL_HOR";
                string time = DateTime.UtcNow.ToString("yyyyMMdd") + "000000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall24.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "24小时降水量图", time, colorpath, "h");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }

        private void DayRainFull0808()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_Time_0808";
                string featureName = "08-08时日降水量";
                string dataCode = "SURF_CHN_MUL_DAY";
                string time = DateTime.UtcNow.AddDays(-1).ToString("yyyyMMdd") + "000000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall24.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "08-08时日降水量图", time, colorpath, "d");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }

        private void DayRainFull0820()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_Time_0820";
                string featureName = "08-20时日降水量";
                string dataCode = "SURF_CHN_MUL_DAY";
                string time = DateTime.UtcNow.AddDays(-1).ToString("yyyyMMdd") + "000000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall24.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "08-20时日降水量图", time, colorpath, "d");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }

        private void DayRainFull2008()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_Time_2008";
                string featureName = "20-08时日降水量";
                string dataCode = "SURF_CHN_MUL_DAY";
                string time = DateTime.UtcNow.AddDays(-1).ToString("yyyyMMdd") + "000000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall24.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "20-08时日降水量图", time, colorpath, "d");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }

        private void DayRainFull2020()
        {
            try
            {
                //参数
                string interfaceName = "getSurfEleInRegionByTime";
                string returnValue = "Lat,Lon,PRE_Time_2020";
                string featureName = "20-20时日降水量";
                string dataCode = "SURF_CHN_MUL_DAY";
                string time = DateTime.UtcNow.AddDays(-1).ToString("yyyyMMdd") + "000000";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\Rainfall24.txt";
                CreateMap.CreateFeatureMap(interfaceName, returnValue, dataCode, featureName, "20-20时日降水量图", time, colorpath, "d");
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省雨量数据生成失败#{0}：{1}", DateTime.Now, ex.Message));
            }
        }
        #endregion
    }
}
